import {BaseRenderer} from "./base-renderer";
import {h, resolveComponent} from "vue";
import {cloneDeep} from "lodash";
import {TableRender} from "../index.ts";

/**
 * 表格渲染器
 */
export class TableRenderer extends BaseRenderer {
    render(item: TableRender<any, any, any>, propsData: any, emit: any) {
        const {prop, props, events, width, minWidth} = item;
        const Type = resolveComponent('el-table-column');

        // 处理事件
        const normalizedEvents = this.processEvents(events);

        // 渲染组件
        return h(Type, {
            prop: prop,
            width: width,
            minWidth: minWidth,
            ...cloneDeep(props),
            ...normalizedEvents
        }, item.renderFn ? {
            default: (data: any) => item.renderFn ? item.renderFn(data) : null
        } : undefined);
    }
}